<template>
	<view class="body">
		<!-- tab切换 -->
		<swiper-tab-head
		:tabBars="tabBars" 
		:tabIndex="tabIndex"
		@tabtap="tabtap"
		scrollItemStyle="width:33%;"
		scrollStyle="border-bottom:0;">
		</swiper-tab-head>
		
		<!-- 好友列表 -->
		<!-- <block v-for="(item,index) in list" :key="index">
			<user-list :item="item" :index="index"></user-list>
		</block> -->
		
		<view class="uni-tab-bar">
			<swiper class="swiper-box" 
			:style="{height:swiperheight+'px'}" 
			:current="tabIndex"
			@change="tabChange">
				<swiper-item v-for="(items,index) in newsList" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length>0">
							<!-- 图文列表 -->
							<block v-for="(item,index1) in items.list" :key="index1">
								<user-list :item="item" :index="index1"></user-list>
							</block>
							<!-- 上拉加载 -->
							<load-more :loadtext="items.loadtext"></load-more>
						</template>
						<!-- 无内容默认 -->
						<template v-else>
							<no-thing></no-thing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import swiperTabHead from "../../components/index/swiper-tab-head.vue"
	import userList from "../../components/user-list/user-list.vue"
	import loadMore from "../../components/common/load-more.vue";
	import noThing from "../../components/common/no-thing.vue";
	export default {
		components:{
			swiperTabHead,
			userList,
			loadMore,
			noThing
		},
		data() {
			return {
				tabIndex:0,
				swiperheight:500,
				tabIndex:0,
				tabBars:[
					{name:'互关',id:'huguan',num:10},
					{name:'关注',id:'guanzhu',num:20},
					{name:'粉丝',id:'zuixin',num:30}
				],
				newsList:[
					{
						loadtext:"上拉加载更多",
						list:[
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							},
						]
					},
					{
						loadtext:"上拉加载更多",
						list:[
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							}
						]
					},
					{
						loadtext:"上拉加载更多",
						list:[
							{
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/img/ruiwen.jpg",
								username:"咕咕",
								age:25,
								sex:0,
								isguanzhu:true
							}
						]
					},
				],			
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success:(res)=> {
					let height = res.windowHeight - uni.upx2px(100)
					this.swiperheight = height
				}
			})
		},
		//监听导航按钮
		onNavigationBarButtonTap(e) {
			if(e.index==0){
				uni.navigateBack({
					delta:1
				});
			}
		},
		methods: {
			tabtap(index){
				this.tabIndex=index
			},
			// 滑动事件
			tabChange(e){
				this.tabIndex = e.detail.current
			},
			// 上拉加载
			loadmore(index){
				if(this.newsList[index].loadtext!=='上拉加载更多'){return;}
				//修改状态
				this.newsList[index].loadtext="加载中...";
				//获取数据
				setTimeout(()=>{
					//获取完成
					let obj = {
								userpic:"../../static/img/pika.jpg",
								username:"奇奇",
								age:20,
								sex:1,
								isguanzhu:false
							};
					this.newsList[index].list.push(obj)
					this.newsList[index].loadtext='上拉加载更多'
				},1000)
			},
		}
	}
</script>

<style>

</style>
